package com.itheima.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtils {
    private static String KEY = "fenglai";
    private static Long TIME = 43200000L;

    public static String getJwt(Map<String, Object> claims) {
        String jwt = Jwts.builder().signWith(SignatureAlgorithm.HS256, KEY)
                .setClaims(claims)
                .setExpiration(new Date(System.currentTimeMillis() + TIME))
                .compact();
        return jwt;
    }

    public static Claims parserJwt(String jwt) {
        Claims claims = Jwts.parser()
                .setSigningKey(KEY)
                .parseClaimsJws(jwt)
                .getBody();
        return claims;
    }
}
